/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.job;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserEnterpriseCollection;
import com.thinkgem.jeesite.modules.hk.sys.service.job.HkUserEnterpriseCollectionService;

/**
 * 企业收藏人才Controller
 * @author 罗天文
 * @version 2018-07-25
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/job/hkUserEnterpriseCollection")
public class HkUserEnterpriseCollectionController extends BaseController {

	@Autowired
	private HkUserEnterpriseCollectionService hkUserEnterpriseCollectionService;
	
	@ModelAttribute
	public HkUserEnterpriseCollection get(@RequestParam(required=false) String id) {
		HkUserEnterpriseCollection entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserEnterpriseCollectionService.get(id);
		}
		if (entity == null){
			entity = new HkUserEnterpriseCollection();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:job:hkUserEnterpriseCollection:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserEnterpriseCollection hkUserEnterpriseCollection, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserEnterpriseCollection> page = hkUserEnterpriseCollectionService.findPage(new Page<HkUserEnterpriseCollection>(request, response), hkUserEnterpriseCollection); 
		model.addAttribute("page", page);
		return "hk/sys/job/hkUserEnterpriseCollectionList";
	}

	@RequiresPermissions("sys:job:hkUserEnterpriseCollection:view")
	@RequestMapping(value = "form")
	public String form(HkUserEnterpriseCollection hkUserEnterpriseCollection, Model model) {
		model.addAttribute("hkUserEnterpriseCollection", hkUserEnterpriseCollection);
		return "hk/sys/job/hkUserEnterpriseCollectionForm";
	}

	@RequiresPermissions("sys:job:hkUserEnterpriseCollection:edit")
	@RequestMapping(value = "save")
	public String save(HkUserEnterpriseCollection hkUserEnterpriseCollection, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserEnterpriseCollection)){
			return form(hkUserEnterpriseCollection, model);
		}
		hkUserEnterpriseCollectionService.save(hkUserEnterpriseCollection);
		addMessage(redirectAttributes, "保存企业收藏人才成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserEnterpriseCollection/?repage";
	}
	
	@RequiresPermissions("sys:job:hkUserEnterpriseCollection:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserEnterpriseCollection hkUserEnterpriseCollection, RedirectAttributes redirectAttributes) {
		hkUserEnterpriseCollectionService.delete(hkUserEnterpriseCollection);
		addMessage(redirectAttributes, "删除企业收藏人才成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserEnterpriseCollection/?repage";
	}

}